package de.uhlesoluschns.opensearch.ui;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.PreferenceActivity;
import de.uhlesoluschns.opensearch.R;

public class Preferences extends PreferenceActivity implements OnSharedPreferenceChangeListener {
	
	public static final String AOS_SUGGESTIONS = "aos_suggestions";
	public static final String AOS_POST_SEARCH = "aos_post_search";
	public static final String SELECTED_PROVIDER = "selectedProvider";
	
	private CheckBoxPreference aosSuggestions;
	private CheckBoxPreference aosPostSearch;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.preferences);
		
		aosSuggestions = (CheckBoxPreference) getPreferenceScreen().findPreference(AOS_SUGGESTIONS);
		aosPostSearch = (CheckBoxPreference) getPreferenceScreen().findPreference(AOS_POST_SEARCH);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		aosPostSearch.setChecked(aosSuggestions.isChecked());
		getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
	}
	
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
		if(AOS_SUGGESTIONS.equals(key)) {
			aosPostSearch.setChecked(aosSuggestions.isChecked());
		}
	}
	
}
